package cn.edu.neusoft.yuejian12.Fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.yuejian12.Adapter.ClubInfoAdapter;
import cn.edu.neusoft.yuejian12.JavaBean.Club;
import cn.edu.neusoft.yuejian12.Model.ClubModel;
import cn.edu.neusoft.yuejian12.R;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by 木子李 on 2017/10/18.
 */

public class ClubInfoFragment extends Fragment {
    private RecyclerView recyclerView;
    private Context mContext;
    private String club_id;
    private Club clubinfo;
    private ImageView masterPhoto;
    private TextView masterName,clubContent,club_tell,masterInfo;
    private List<Club.ClubteacherEntity> Data;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.club_info_fragment,container,false);
        masterName = (TextView) view.findViewById(R.id.master_name);
        clubContent = (TextView) view.findViewById(R.id.club_Content);
        club_tell = (TextView) view.findViewById(R.id.club_tell_1);
        masterInfo = (TextView) view.findViewById(R.id.master_info);
        masterPhoto = (ImageView) view.findViewById(R.id.master_pic);
        Intent intent = getActivity().getIntent();
        club_id = intent.getStringExtra("club_id");
        recyclerView = (RecyclerView) view.findViewById(R.id.masterinfo_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        showData();
        return view;
    }

    private void showData(){
        ClubModel clubModel = new ClubModel();
        Call<Club> call = clubModel.getclubinfo(club_id);
        call.enqueue(new Callback<Club>() {
            @Override
            public void onResponse(Call<Club> call, Response<Club> response) {
                clubinfo = response.body();
                clubContent.setText(clubinfo.getIntroduction());
                club_tell.setText(clubinfo.getClub_tel());
                Data=response.body().getClubteacher();
                recyclerView.setAdapter(new ClubInfoAdapter(getActivity(),Data));
            }
            @Override
            public void onFailure(Call<Club> call, Throwable t) {

            }
        });
    }
}
